﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfParsingException : Exception
    {
        protected string errorDescription;
        protected int errorFilePosition;
        protected string lastReadText;
        protected string textAfterPosition;

        public PdfParsingException(FileReader reader, string errorDescription = "no description", Exception innerException = null)
            : base("", innerException)
        {
            this.errorFilePosition = reader.Position;
            this.lastReadText = reader.LastReadText;
            this.errorDescription = errorDescription;
            this.textAfterPosition = reader.ReadLine();
        }

        public override string Message
        {
            get
            {
                return String.Format("Parsing error at file position {0}! {1}\nLast read text: {2}\nText from position: {3}",
                    new object[] { this.errorFilePosition, this.errorDescription, this.lastReadText, this.textAfterPosition });
            }
        }
    }
}
